home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Technotools
/
Technotools (Chestnut CD-ROM)(1993).ISO
/
lang_c
/
cug172
/
eclosu.c
< prev
next >
Wrap
C/C++ Source or Header
|
1986-02-05
|
2KB
|
65 lines
/*
HEADER: CUG nnn.nn;
TITLE: LEX - A Lexical Analyser Generator
VERSION: 1.0 for IBM-PC
DATE: Jan 30, 1985
DESCRIPTION: A Lexical Analyser Generator. From UNIX
KEYWORDS: Lexical Analyser Generator YACC C PREP
SYSTEM: IBM-PC and Compatiables
FILENAME: ECLOSU.C
WARNINGS: This program is not for the casual user. It will
be useful primarily to expert developers.
CRC: N/A
SEE-ALSO: YACC and PREP
AUTHORS: Scott Guthery 11100 leafwood lane Austin, TX 78750
COMPILERS: DESMET-C
REFERENCES: UNIX Systems Manuals
*/
/*
* Copyright (c) 1978 Charles H. Forsyth
*/
#include <stdio.h>
#include "lexlex.h"
/*
* Construct the epsilon closure of a given set; this is the set of states
* that may be reached by some number of epsilon transitions from that state.
*/
struct set *
eclosure(t)
struct set *t;
{
register struct nfa *np, *xp;
register i;
struct nfa **sp, **tp, **ip, *stack[MAXNFA], *temp[MAXNFA];
tp = temp;
for (sp = stack, i = 0; i < t->s_len; i++)
if (sp <= stack+MAXNFA)
*tp++ = *sp++ = t->s_els[i];
else {
error("Stack overflow in `eclosure'");
exit(1);
}
while (sp > stack) {
np = *--sp;
if (np->n_char==EPSILON)
for (i = 0; i < 2; i++)
if (xp = np->n_succ[i]) {
for (ip = temp; ip < tp;)
if (*ip++ == xp)
goto cont;
if (tp >= temp+MAXNFA) {
error("eclosure: list overflow");
exit(1);
}
*sp++ = *tp++ = xp;
cont:;
}
}
t = newset(temp, tp-temp, 1);
return(t);
}